﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JumbotPay.API.YunGouOS.WxPay;
namespace JumbotPay.WebFile.YungGouOS_Wxpay_Mobile
{
    public partial class _order_query : JumbotPay.UI.BasicPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string _order_id = q("order_id");
            string _out_trade_no = q("out_trade_no");
            object[] value = new JumbotPay.DAL.OrderDAL().GetOrderFields("yungouos_wxpay", _order_id, _out_trade_no, "appid,out_trade_no,account_wxpay,pay_status");
            if (value != null)
            {
                string appid = value[0].ToString();
                _out_trade_no = value[1].ToString();
                string _account_wxpay = value[2].ToString();
                int pay_status = Str2Int(value[3].ToString());
                if (pay_status == 1)
                {
                    Response.Write(JsonResult(1, "success"));
                }
                else
                {
                    Response.Write(JsonResult(0, "waiting"));
                }
                //try
                //{
                //    string result = new OrderQuery().Run( _out_trade_no, _account_wxpay);//不要暴露流水号

                //    Newtonsoft.Json.Linq.JObject jo = Newtonsoft.Json.Linq.JObject.Parse(result);
                //    string _code = jo["code"].ToString();
                //    if (_code == "0")
                //    {
                //        if (jo["data"]["payStatus"].ToString()=="1")
                //        {
                //            if (new JumbotPay.DAL.OrderDAL().UpdateOrder("yungouos_wxpay", _out_trade_no, "", ""))
                //            {
                //            }
                //            Response.Write(JsonResult(1, "success"));
                //        }
                //        else
                //        {
                //            JumbotPay.Utils.Logs.Error("wxpay_OrderQuery", result, false);
                //            Response.Write(JsonResult(0, jo["msg"].ToString()));
                //        }
                //    }
                //    else
                //    {
                //        JumbotPay.Utils.Logs.Error("wxpay_OrderQuery", result, false);
                //        Response.Write(JsonResult(0, jo["msg"].ToString()));

                //    }

                //}
                //catch (WxPayException ex)
                //{
                //    Response.Write(JsonResult(0, ex.Message));
                //}
                //catch (Exception ex)
                //{
                //    Response.Write(JsonResult(0, ex.Message));
                //}
            }else
                Response.Write(JsonResult(0, "请确认订单号或商户单号"));
        }
    }
}